package com.dly.hope.controller;

import com.dly.hope.constant.R;
import com.dly.hope.service.TemplateService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.http.MediaType;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletResponse;

/**
 * 模板相关
 * @author linyu.dai
 */
@RestController
@Api(tags = "模板相关")
@RequestMapping(value = "/temp")
public class TemplateController extends BaseController{

    @Resource
    private TemplateService templateService;


    @ApiOperation(value = "上传模板",consumes = MediaType.MULTIPART_FORM_DATA_VALUE)
    @PostMapping(value = "/upload", consumes = MediaType.MULTIPART_FORM_DATA_VALUE)
    public ResponseEntity<R<Void>> update(MultipartFile file){
        //两个都要表示为文件form类型
        templateService.update(file);
        return operate(this::success);
    }

    @ApiOperation(value = "下载模板")
    @GetMapping("/download")
    public ResponseEntity<R<Void>> download(HttpServletResponse response){
        templateService.download(response);
        return operate(this::success);
    }
}
